﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_T_SYS_USER
	/// </summary>
	public partial class DAL_T_SYS_USER
	{
		public DAL_T_SYS_USER()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string SYS_USER_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_SYS_USER");
			strSql.Append(" where SYS_USER_ID=:SYS_USER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_USER_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_USER_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ChinaSoft.Model.Model_T_SYS_USER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_SYS_USER(");
			strSql.Append("SYS_USER_ID,ADDRESS,BIRTHDAY,GROUP_ID,GROUP_NAME,LOGIN_NAME,E_MAIL,NAME,PASSWORD,PASSWORD_ANSWER,PWD_QUESTION,POSTAL_CODE,SEX,TELEPHONE,CREATE_TIME,CREATOR_ID,CREATOR_NAME,UPDATE_TIME,UPDATOR_ID,UPDATOR_NAME)");
			strSql.Append(" values (");
			strSql.Append(":SYS_USER_ID,:ADDRESS,:BIRTHDAY,:GROUP_ID,:GROUP_NAME,:LOGIN_NAME,:E_MAIL,:NAME,:PASSWORD,:PASSWORD_ANSWER,:PWD_QUESTION,:POSTAL_CODE,:SEX,:TELEPHONE,:CREATE_TIME,:CREATOR_ID,:CREATOR_NAME,:UPDATE_TIME,:UPDATOR_ID,:UPDATOR_NAME)");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_USER_ID", OracleType.VarChar,40),
					new OracleParameter(":ADDRESS", OracleType.NVarChar),
					new OracleParameter(":BIRTHDAY", OracleType.DateTime),
					new OracleParameter(":GROUP_ID", OracleType.VarChar,40),
					new OracleParameter(":GROUP_NAME", OracleType.NVarChar),
					new OracleParameter(":LOGIN_NAME", OracleType.NVarChar),
					new OracleParameter(":E_MAIL", OracleType.NVarChar),
					new OracleParameter(":NAME", OracleType.NVarChar),
					new OracleParameter(":PASSWORD", OracleType.NVarChar),
					new OracleParameter(":PASSWORD_ANSWER", OracleType.NVarChar),
					new OracleParameter(":PWD_QUESTION", OracleType.NVarChar),
					new OracleParameter(":POSTAL_CODE", OracleType.NVarChar),
					new OracleParameter(":SEX", OracleType.NVarChar),
					new OracleParameter(":TELEPHONE", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":CREATOR_NAME", OracleType.NVarChar),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATOR_NAME", OracleType.NVarChar)};
			parameters[0].Value = model.SYS_USER_ID;
			parameters[1].Value = model.ADDRESS;
			parameters[2].Value = model.BIRTHDAY;
			parameters[3].Value = model.GROUP_ID;
			parameters[4].Value = model.GROUP_NAME;
			parameters[5].Value = model.LOGIN_NAME;
			parameters[6].Value = model.E_MAIL;
			parameters[7].Value = model.NAME;
			parameters[8].Value = model.PASSWORD;
			parameters[9].Value = model.PASSWORD_ANSWER;
			parameters[10].Value = model.PWD_QUESTION;
			parameters[11].Value = model.POSTAL_CODE;
			parameters[12].Value = model.SEX;
			parameters[13].Value = model.TELEPHONE;
			parameters[14].Value = model.CREATE_TIME;
			parameters[15].Value = model.CREATOR_ID;
			parameters[16].Value = model.CREATOR_NAME;
			parameters[17].Value = model.UPDATE_TIME;
			parameters[18].Value = model.UPDATOR_ID;
			parameters[19].Value = model.UPDATOR_NAME;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_T_SYS_USER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_SYS_USER set ");
			strSql.Append("ADDRESS=:ADDRESS,");
			strSql.Append("BIRTHDAY=:BIRTHDAY,");
			strSql.Append("GROUP_ID=:GROUP_ID,");
			strSql.Append("GROUP_NAME=:GROUP_NAME,");
			strSql.Append("LOGIN_NAME=:LOGIN_NAME,");
			strSql.Append("E_MAIL=:E_MAIL,");
			strSql.Append("NAME=:NAME,");
			strSql.Append("PASSWORD=:PASSWORD,");
			strSql.Append("PASSWORD_ANSWER=:PASSWORD_ANSWER,");
			strSql.Append("PWD_QUESTION=:PWD_QUESTION,");
			strSql.Append("POSTAL_CODE=:POSTAL_CODE,");
			strSql.Append("SEX=:SEX,");
			strSql.Append("TELEPHONE=:TELEPHONE,");
			strSql.Append("CREATE_TIME=:CREATE_TIME,");
			strSql.Append("CREATOR_ID=:CREATOR_ID,");
			strSql.Append("CREATOR_NAME=:CREATOR_NAME,");
			strSql.Append("UPDATE_TIME=:UPDATE_TIME,");
			strSql.Append("UPDATOR_ID=:UPDATOR_ID,");
			strSql.Append("UPDATOR_NAME=:UPDATOR_NAME");
			strSql.Append(" where SYS_USER_ID=:SYS_USER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ADDRESS", OracleType.NVarChar),
					new OracleParameter(":BIRTHDAY", OracleType.DateTime),
					new OracleParameter(":GROUP_ID", OracleType.VarChar,40),
					new OracleParameter(":GROUP_NAME", OracleType.NVarChar),
					new OracleParameter(":LOGIN_NAME", OracleType.NVarChar),
					new OracleParameter(":E_MAIL", OracleType.NVarChar),
					new OracleParameter(":NAME", OracleType.NVarChar),
					new OracleParameter(":PASSWORD", OracleType.NVarChar),
					new OracleParameter(":PASSWORD_ANSWER", OracleType.NVarChar),
					new OracleParameter(":PWD_QUESTION", OracleType.NVarChar),
					new OracleParameter(":POSTAL_CODE", OracleType.NVarChar),
					new OracleParameter(":SEX", OracleType.NVarChar),
					new OracleParameter(":TELEPHONE", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":CREATOR_NAME", OracleType.NVarChar),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATOR_NAME", OracleType.NVarChar),
					new OracleParameter(":SYS_USER_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.ADDRESS;
			parameters[1].Value = model.BIRTHDAY;
			parameters[2].Value = model.GROUP_ID;
			parameters[3].Value = model.GROUP_NAME;
			parameters[4].Value = model.LOGIN_NAME;
			parameters[5].Value = model.E_MAIL;
			parameters[6].Value = model.NAME;
			parameters[7].Value = model.PASSWORD;
			parameters[8].Value = model.PASSWORD_ANSWER;
			parameters[9].Value = model.PWD_QUESTION;
			parameters[10].Value = model.POSTAL_CODE;
			parameters[11].Value = model.SEX;
			parameters[12].Value = model.TELEPHONE;
			parameters[13].Value = model.CREATE_TIME;
			parameters[14].Value = model.CREATOR_ID;
			parameters[15].Value = model.CREATOR_NAME;
			parameters[16].Value = model.UPDATE_TIME;
			parameters[17].Value = model.UPDATOR_ID;
			parameters[18].Value = model.UPDATOR_NAME;
			parameters[19].Value = model.SYS_USER_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string SYS_USER_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_SYS_USER ");
			strSql.Append(" where SYS_USER_ID=:SYS_USER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_USER_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_USER_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string SYS_USER_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_SYS_USER ");
			strSql.Append(" where SYS_USER_ID in ("+SYS_USER_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_T_SYS_USER GetModel(string SYS_USER_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SYS_USER_ID,ADDRESS,BIRTHDAY,GROUP_ID,GROUP_NAME,LOGIN_NAME,E_MAIL,NAME,PASSWORD,PASSWORD_ANSWER,PWD_QUESTION,POSTAL_CODE,SEX,TELEPHONE,CREATE_TIME,CREATOR_ID,CREATOR_NAME,UPDATE_TIME,UPDATOR_ID,UPDATOR_NAME from T_SYS_USER ");
			strSql.Append(" where SYS_USER_ID=:SYS_USER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_USER_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_USER_ID;

			ChinaSoft.Model.Model_T_SYS_USER model=new ChinaSoft.Model.Model_T_SYS_USER();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["SYS_USER_ID"]!=null && ds.Tables[0].Rows[0]["SYS_USER_ID"].ToString()!="")
				{
					model.SYS_USER_ID=ds.Tables[0].Rows[0]["SYS_USER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ADDRESS"]!=null && ds.Tables[0].Rows[0]["ADDRESS"].ToString()!="")
				{
					model.ADDRESS=ds.Tables[0].Rows[0]["ADDRESS"].ToString();
				}
				if(ds.Tables[0].Rows[0]["BIRTHDAY"]!=null && ds.Tables[0].Rows[0]["BIRTHDAY"].ToString()!="")
				{
					model.BIRTHDAY=DateTime.Parse(ds.Tables[0].Rows[0]["BIRTHDAY"].ToString());
				}
				if(ds.Tables[0].Rows[0]["GROUP_ID"]!=null && ds.Tables[0].Rows[0]["GROUP_ID"].ToString()!="")
				{
					model.GROUP_ID=ds.Tables[0].Rows[0]["GROUP_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["GROUP_NAME"]!=null && ds.Tables[0].Rows[0]["GROUP_NAME"].ToString()!="")
				{
					model.GROUP_NAME=ds.Tables[0].Rows[0]["GROUP_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LOGIN_NAME"]!=null && ds.Tables[0].Rows[0]["LOGIN_NAME"].ToString()!="")
				{
					model.LOGIN_NAME=ds.Tables[0].Rows[0]["LOGIN_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["E_MAIL"]!=null && ds.Tables[0].Rows[0]["E_MAIL"].ToString()!="")
				{
					model.E_MAIL=ds.Tables[0].Rows[0]["E_MAIL"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NAME"]!=null && ds.Tables[0].Rows[0]["NAME"].ToString()!="")
				{
					model.NAME=ds.Tables[0].Rows[0]["NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PASSWORD"]!=null && ds.Tables[0].Rows[0]["PASSWORD"].ToString()!="")
				{
					model.PASSWORD=ds.Tables[0].Rows[0]["PASSWORD"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PASSWORD_ANSWER"]!=null && ds.Tables[0].Rows[0]["PASSWORD_ANSWER"].ToString()!="")
				{
					model.PASSWORD_ANSWER=ds.Tables[0].Rows[0]["PASSWORD_ANSWER"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PWD_QUESTION"]!=null && ds.Tables[0].Rows[0]["PWD_QUESTION"].ToString()!="")
				{
					model.PWD_QUESTION=ds.Tables[0].Rows[0]["PWD_QUESTION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["POSTAL_CODE"]!=null && ds.Tables[0].Rows[0]["POSTAL_CODE"].ToString()!="")
				{
					model.POSTAL_CODE=ds.Tables[0].Rows[0]["POSTAL_CODE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SEX"]!=null && ds.Tables[0].Rows[0]["SEX"].ToString()!="")
				{
					model.SEX=ds.Tables[0].Rows[0]["SEX"].ToString();
				}
				if(ds.Tables[0].Rows[0]["TELEPHONE"]!=null && ds.Tables[0].Rows[0]["TELEPHONE"].ToString()!="")
				{
					model.TELEPHONE=ds.Tables[0].Rows[0]["TELEPHONE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_TIME"].ToString()!="")
				{
					model.CREATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATOR_ID"]!=null && ds.Tables[0].Rows[0]["CREATOR_ID"].ToString()!="")
				{
					model.CREATOR_ID=ds.Tables[0].Rows[0]["CREATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATOR_NAME"]!=null && ds.Tables[0].Rows[0]["CREATOR_NAME"].ToString()!="")
				{
					model.CREATOR_NAME=ds.Tables[0].Rows[0]["CREATOR_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString()!="")
				{
					model.UPDATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_ID"]!=null && ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString()!="")
				{
					model.UPDATOR_ID=ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_NAME"]!=null && ds.Tables[0].Rows[0]["UPDATOR_NAME"].ToString()!="")
				{
					model.UPDATOR_NAME=ds.Tables[0].Rows[0]["UPDATOR_NAME"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SYS_USER_ID,ADDRESS,BIRTHDAY,GROUP_ID,GROUP_NAME,LOGIN_NAME,E_MAIL,NAME,PASSWORD,PASSWORD_ANSWER,PWD_QUESTION,POSTAL_CODE,SEX,TELEPHONE,CREATE_TIME,CREATOR_ID,CREATOR_NAME,UPDATE_TIME,UPDATOR_ID,UPDATOR_NAME ");
			strSql.Append(" FROM T_SYS_USER ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_SYS_USER ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.SYS_USER_ID desc");
			}
			strSql.Append(")AS Row, T.*  from T_SYS_USER T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "T_SYS_USER";
			parameters[1].Value = "SYS_USER_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

